<script>
	import request from '/common/request.js';
	export default {
		globalData: {
			showLogin: false,
			//apiUrl: 'http://47.122.57.26:8080',
			// apiUrl1: 'http://47.122.57.26:8080',
			// apiUrl: 'http://127.0.0.1:9000',
			//  apiUrl1: 'http://47.122.57.26:8080',
			// apiUrl: 'http://47.122.46.76:8080',
			// apiUrl1: 'http://47.122.46.76:8080'	,
			apiUrl1: 'https://www.shejiai.cc',
			apiUrl: 'https://www.shejiai.cc'
		},
		onLaunch: function() {
			console.log('App Launch')
			setInterval(function() {
				var token = uni.getStorageSync("token");
				if (token) {
					const that = this;
					const url = getApp().globalData.apiUrl + "/api/v1/user/messageInfo";
					uni.request({
						url: url, //由基础路径和接口地址
						method: "GET", //请求的方式必须大写
						data: {
							page: 0,
							size: 100
						}, //参数
						header: {
							'Content-Type': 'application/json',
							'satoken': token
						},
						success: (res) => {

							if (res.data.code == 0) {

								var newTime = res.data.data.newTime;
								uni.setStorageSync("newTime", newTime);
								var readTime = uni.getStorageSync("readTime");
								if (newTime) {
									var red = readTime != newTime
									console.log(readTime)
									console.log(newTime)
									console.log(red)
									if (red) {
										uni.showTabBarRedDot({
											index: 3
										})
									}
								}
								var notice = res.data.data.newSystemMsg.notice;
								if (notice) {
									var name = notice.name;
									var content = notice.content;
									uni.setStorageSync("notice", name + "------" + content);
								}
								console.log('返回正确回调', res)
							} else {
								uni.showToast({
									title: res.data.message
								})
							}
						},
						//失败调用reject，
						fail: (err) => {
							var temp = {};
							temp.code = 777777;
							temp.message = "网络请求错误";
							temp.data = err;
							console.log(err)
							reject(temp)
						}
					});
				}
			}, 10000)
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	uni-tabbar .uni-tabbar__reddot {
		background-color: #D000FF;
	}
	
	/*每个页面公共css */
</style>